package com.xingkeduo.pojo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;

/**
 * 订单状态
 *
 * @author chi  2019-02-13 15:53
 **/
@Slf4j
@Getter
public enum OrderStatus {


    CLOSE(-4, "已关闭") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) || match(new OrderStatus[]{}, orderStatus);
        }
    },
    CANCEL(-3, "已取消") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{}, orderStatus);
        }
    },
    REFUND_DONE(-2, "已退款") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{}, orderStatus);
        }
    },
    REFUND_APPLY(-1, "退款待审") {//
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{REFUND_REGECT, REFUND_ACCEPT}, orderStatus);
        }
    },
    NOT_PAY(0, "待支付") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{CANCEL, CLOSE, PAID,EVALUATION_DONE}, orderStatus);
        }
    },
    PAID(1, "待服务") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{IN_SERVICE, OVER_NUMBER, REFUND_DONE}, orderStatus);
        }
    },
    //废弃
    @Deprecated
    HAIRCUT_DONE(2, "等待评价") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{CANCEL, REFUND_DONE}, orderStatus);
        }
    },
    EVALUATION_DONE(3, "服务完成") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{REFUND_DONE, REFUND_APPLY}, orderStatus);
        }
    },
    //废弃
    @Deprecated
    SHARE_DONE(4, "已分享") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{}, orderStatus);
        }
    },
    OVER_NUMBER(5, "已过号") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{PAID, REFUND_DONE}, orderStatus);
        }
    },
    REFUND_ERROR(6, "退款失败") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{CANCEL, REFUND_DONE}, orderStatus);
        }
    },
    REFUND_ACCEPT(7, "退款中") {//审核通过
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{REFUND_ERROR, REFUND_DONE}, orderStatus);
        }
    },
    IN_SERVICE(8, "服务中") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{EVALUATION_DONE}, orderStatus);
        }
    },
    REFUND_REGECT(9, "退款驳回") {
        @Override
        public boolean covert(OrderStatus orderStatus) {
            return this.equals(orderStatus) ||  match(new OrderStatus[]{REFUND_APPLY, REFUND_ACCEPT}, orderStatus);
        }
    },;

    @EnumValue
    private int key;

    private String value;

    OrderStatus(int key, String value) {
        this.key = key;
        this.value = value;
    }

    public abstract boolean covert(OrderStatus orderStatus);

    private static boolean match(OrderStatus[] orderStatuses, OrderStatus orderStatus) {
        List<OrderStatus> orderStatuses1 = Arrays.asList(orderStatuses);
        return orderStatuses1.contains(orderStatus);
    }


    /**
     * 返回状态,0,开始态,1,中间态,2,最终态
     * @return
     */
    public int getEndStatus(){
        if(NOT_PAY.equals(this)){
            return 0;
        }
        if(CANCEL.equals(this) || CLOSE.equals(this)
            || EVALUATION_DONE.equals(this) || REFUND_DONE.equals(this)){

            return 2;
        }
        return 1;
    }


}
